package com.qidianit.mes.sys.controller;

import com.github.pagehelper.PageInfo;
import com.qidianit.mes.pojo.Customer;
import com.qidianit.mes.pojo.Result;
import com.qidianit.mes.pojo.Supplier;
import com.qidianit.mes.sys.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ author: 周晓轩
 * @ company 起点编程
 * @ time: 2025/9/16 - 20:26
 * @ Description:
 */
@RestController
@RequestMapping("/supplier")
public class SupplierController {
    @Autowired
    private SupplierService supplierService;

    @GetMapping("page")
    public Result<PageInfo<Supplier>> list(Supplier supplier, @RequestParam(defaultValue = "1")int pageNum, @RequestParam(defaultValue = "10")int size){
        return supplierService.selectList(supplier,pageNum,size);
    };

    @GetMapping("/code/{code}")
    public Result<Supplier> getByCode(@PathVariable("code") String code){
        return supplierService.selectByCode(code);
    }

    @PostMapping("/add")
    public Result<Supplier> save(@RequestBody Supplier supplier){
        return supplierService.addSupplier(supplier);
    };

    @PutMapping("/update")
    public Result update(@RequestBody Supplier supplier){
        return supplierService.updateSupplierById(supplier);
    };

    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Long id){
        return supplierService.deleteById(id);
    }

    @DeleteMapping("/batchDelete")
    public Result batchDelete(Long [] id){
        return supplierService.batchDelete(id);
    };
}
